Reworked JS so it's faster