I have refactored and on many places fixed your code. You can pull it right now.