Adding initial code and test for chaining. TODO bugs to fix