fixed some horrible bugs