Code restructure and edits