Fix undefined constant error, refactor