Clearing the code and optimizing some parts