seem to have fixed scoping issue by chaning where leave happens