Small changes, working script. May have problems with char encoding.