copied over corrected code