Revert "alot of clean up code and optimisation"

This reverts commit 340c87d8a1f1b5dde1c3cbc7513d0edf6961f9aa.