Version3 based on Dirk's code