refactored a bit, rendering seems to work now