Updated comments and introduced some abstractions.