Rearrange and organize methods, add comments documenting functionality and sample flash fix