added function call. and modified variables and calculations