added random function, perl-tidied, change appropriate methods to functions