Revamped version
handled error stream
fixes
Code cleanup