added backward encoder functionality (needs testing)