Fixed Dawei's bugs, everything works now.