fix bugs, add loads more documentation