Fix bugs and remove Java code, which will be moved