updated with chaining and sequence
updated with flatMap
renamed
Generic state added