reviewed and cleaned up