added clean function
added comments and removed one duplicate memset