fixed gallery and cleaned up code