Minor code simplification for Containers api

Just a little bit simpler. Also should stop comparing container ids when "beforeId" is found.