Converted code to use arrays, cleaned up code as well