made optional and direction configurable and fixed it