Refractor code and make it work..