Working version after several hours of intense braindamage