Add logging functionality and fixed timing issues