restructured code to use call/ret