Changed the code to work correctly with convert to