fix some errors and add some spec tests