cleaned up code, made extra type to prevent nullpointer exceptions. error print demo added to test