working non-optimized code