final functional version of code