Added spec test and fixed code