added optimized version (all math, less string conversions)