MODIFIED: finished fixing errors