Bug Fixes

Fix bugs on define function and refactored the text format function