friendly mines infrastructure

This set of changes fixes bugs with the friendly mines infrastructure, and makes things more maintainable.