A working version of programming assignment 3, but it needs some code improvements (refactoring)