added lots of tests and refactored gimage