viewport functions rewritten