Some refactoring and APEv2 beginning