Fixed #8. Restructured code