Fixed a few bugs, and merged changes