Refactored Controller

Too gain more performance and  I've refactored the controller. Please have a look.