Revised to fix mistakes & bugs