Refactored code. Added some mozilla style.