clean up and test sapm. needs more work.