Made my algorithm smaller and better