Improved structure of code. Added new code.