massive code clean up