added explicit returns from local functions