Code refactoring

- unused code removed
- main function has become more compact