Fixed initialization when document is loaded