fixed incorrect references
api update
reformat
replaced some functions by api calls