Made main functions simpler and faster, and added attachments to logs.