fixed minor errors and cleaned up code