Added support for return termination
Fixed memory leaks
Other small bug fixes