Comments added, functions fixed