added functions, reduced code