Added credit for idea in stackoverflow