Tidied up hashbang logic