Borrowed code from Doolean, works now [and added forgotten files]