Fixed bugs as pointed out by Wasmoo