Various bug fixes and small additions