Improved definitions and internal refactoring