Added more type checks
Added proper type conversion; fixes test