partially refactored to bitfields