working implemenation with large amounts of code reuse!