Half working Code
Final code before unit testing.