Cleanup some partial code and refactor test