Program is working. Refactoring and commenting needed.