Adding tests for score() and some memory cleanup fixes