Corrected errors and make it work correctly (hope so)