Attemp to adapt existing code