complete overhaul with help of Jeremy