Added spec, changed logic slightly