initial implentation
fixing 'end' issue and adding examples and tests