renamed functions and minor style change