Fix the calculation of max room count
Fix possible empty foreach with array cast
Merge pull request #3 from c4y/master

Issue #1 and #2