Added spec tests and fixed code in client