random bug fixes and minor changes