Fixed random bugs submitted by mirima.