Fixed code issues highlighted by @dereuromark
Created test case to ensure that `allowEmpty` is respected.