Less type conversions, shorter code, minor speedup

Thanks @ElDeveloper!