refactored code. Reordered methods.