Fixing a bug in subdmain calculation