Remove useless closures and clean the code