Some general cleanup to the code and tests