attributes comparaison code from bagpipe and small fixes from them