Serious cleanup, removed unnecessary code, more cleanup in next commit