New version with better coding