Refactor + better app require handling