Cleaning up errors and bugs