Working program
Some refactoring