Fixed a few undefined bugs