Based on lightapp4 svn trunk