Function refactoring and spacing fixes.