Better way to handle errors, reorganize some tasks