Round to nearest spark level instead of truncating.
refactor some code into reusable functions