all functions implemented - final version