Add specs and rearrange code.