Fixed things, close to final version