refactored so that serial can read from a bin file