Fixed bugs and shortened code