refactoring code to take advantage of Cost interpreting empty string as zero