fixed warnings, removed empty lines
refactoring; extracted method, localized variables
changed identation to spaces