If anyone has any suggestsions about performance, code style or better ways of doing it I would be happy for the feedback. E.g. is it better to put all those globals as instance vars on a dummy object?