added another compoenent and did some code cleanup and inlined somestuff to avoid resource leaks