refactor code and cleanup - no changes to functionality