add janbar's changes and clean some more code