correct indent
redesign function entry points to remove redundancy
rename functions more sensibly