Most of functionality done