some cleanup and added comments
Added check for int, before converting