Bug fixes, minor code changes