Improved constants' safety; made validation more general; added tests.