More robust implementation.