Refactoring: moved function 'x_malloc' to reduce dependencies.