fixes #25, fixes #24, fixes #22, fixes #21, fixes #20

general code refactor and improvement with multiple bug fixes.