refactored to use base conversion using numbers instead of strings