Improve handling of non-integer edge cases

Also, refactor for style