Added the fixes suggested by Ryan