MODIFIED: nicer code