general bugs fixes and cleaning