added rst support, refactored a bit