rough functional implementation