Incorporate changes from tmthrgd/mpw-js@5887a8a and enforce counter range