small bug fix and minor refactor