improve logging and add test