Added more logging, bug fixes and output stability