Solution for bounded buffer exercise