Code improvement by making a separate javascript file