Cleaning up the code, removing statics etc.