bug fixes and efficiency changes