Cleaned the code, thanks to SmallJoker