Fixed some bugs in CompositeLayer and added a unit test