adding tim's new codes + modifications