Code: Various bug fixes