The two methods has similar functionality and has complex logic, after this change, the code base would be easier to maintain. For `CAST` function, the behaviour is different than the general purpose `types.Convert`, so I implemented a dedicated function for it.