improved code for O