Added comments and increased modularity