A simple implementation from my homework