completed non-optimized implementation