Tidied up the code a little. Before adding Ransack