Fixed some bugs and merged some files