Bugs fixed, thanks to @ichitaso