Added specs and rewritten internals