Picked up code from aramos remote upstream