Fixed some things and added tests