Code refactoring, added constants, review comments