code optimized, names modified