First implementation. Seems functional.