replace magic string and more refactoring