Refactoring error function and node creation
Factory function for nodes
Error handling