removed old unused functions, code re-factored