Fix a weird bug and optimize code

Let's keep that ;)