Fix missing constant issue + minor refactoring