Fixed couple of bugs and added more testing