Improve functions and structure