Tidied up functions according to Google R Style guide