updated with luke's code and comments