Added functionality and comments