modified write function in thread.php, added validation