merged latest changes from marinos, still unfinished but almost there!