First pass functional implementation