Code Refactoring almost done, Got it working on basic level