Added working code; edited comments