Potential bug fixes and compiler warnings

Nothing too important, but it gets rid of some compiler warnings and could potentially fix bugs.