fixed locks issue and some minor clean up