Added a couple of rspecs and refactored some internals