Cleanup code by Dmitry Shveenkov's review.