Cleaned up code, better debugging. Need error messages.