refactored andThen into a simplified andThen and a map