Fixed some bugs and added better XML comments