Added logging
Some comments for clarity