Refactor tests and adds more documentation