cleaned up dirty render function