Fixs tons of bugs and optimization