Fixed horrible bugs