Refatoring main javascript :D