Refactored code. Split code into separated files.