Final version, all bugs worked out