Moved js out to separate file and improved buffer load