reapplied riley's changes