fixed bugs in finding most compact form