almost all functionality done