prefixed private functions with an underscore
added/changed comments
moved calculation of padding count to a separate function, to allow re-use