Added more comments about the implementation and fixed indentation