added galleries support and other major stuff

see the manual at the beginning of the file to see all the modifications