refactored to use bitwise shits instead of if table